﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering.View_Operaction;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace Catering.Catering_Page.Kufang
{
    public partial class CostDataPieChar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txt_StratDate.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy'})");
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            View_Monitor vm = new View_Monitor();
            string AREAID = DDLTool1.GetDDL_Area();
            string CLASSID = DDLTool1.GetDDL_Class();
            string sTime = txt_StratDate.Text;
            DateTime time = DateTime.Parse("1949-10-01 00:00:11");
            if (sTime.Length == 4)
            {
                DateTime.TryParse(sTime + "-01-01 00:00:11", out time);
            }
            else if (sTime.Length > 5)
            {
                DateTime.TryParse(sTime, out time);
            }
            string TITLE = Bind_Data_to_Controls.Bind_ReportTitle(AREAID, CLASSID, time, "成本比例图");
            string pid = "0";
            if (Session["UserID"] != null) pid = Session["UserID"].ToString();
            DataTable dt = vm.GetCostDataForPieChar(pid, AREAID, CLASSID, ddl_Time.SelectedItem.Value, time, TITLE);
            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;
        }

        protected void ddl_Time_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (ddl_Time.SelectedItem.Value)
            {
                case "Year":
                    txt_StratDate.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy'})");
                    break;
                case "Month":
                    txt_StratDate.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy-MM'})");
                    break;
                default:
                    break;
            }
        }
    }
}